package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CyQuestionRequirement;
import com.ruoyi.system.service.ICyQuestionRequirementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 策义问卷调查：需求调查Controller
 * 
 * @author ruoyi
 * @date 2021-12-30
 */
@Controller
@RequestMapping("/system/requirement")
public class CyQuestionRequirementController extends BaseController
{
    private String prefix = "system/requirement";

    @Autowired
    private ICyQuestionRequirementService cyQuestionRequirementService;

    @RequiresPermissions("system:requirement:view")
    @GetMapping()
    public String requirement()
    {
        return prefix + "/requirement";
    }

    /**
     * 查询策义问卷调查：需求调查列表
     */
    @RequiresPermissions("system:requirement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CyQuestionRequirement cyQuestionRequirement)
    {
        startPage();
        List<CyQuestionRequirement> list = cyQuestionRequirementService.selectCyQuestionRequirementList(cyQuestionRequirement);
        return getDataTable(list);
    }

    /**
     * 导出策义问卷调查：需求调查列表
     */
    @RequiresPermissions("system:requirement:export")
    @Log(title = "策义问卷调查：需求调查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CyQuestionRequirement cyQuestionRequirement)
    {
        List<CyQuestionRequirement> list = cyQuestionRequirementService.selectCyQuestionRequirementList(cyQuestionRequirement);
        ExcelUtil<CyQuestionRequirement> util = new ExcelUtil<CyQuestionRequirement>(CyQuestionRequirement.class);
        return util.exportExcel(list, "策义问卷调查：需求调查数据");
    }

    /**
     * 新增策义问卷调查：需求调查
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存策义问卷调查：需求调查
     */
    @RequiresPermissions("system:requirement:add")
    @Log(title = "策义问卷调查：需求调查", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CyQuestionRequirement cyQuestionRequirement)
    {
        return toAjax(cyQuestionRequirementService.insertCyQuestionRequirement(cyQuestionRequirement));
    }

    /**
     * 修改策义问卷调查：需求调查
     */
    @RequiresPermissions("system:requirement:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CyQuestionRequirement cyQuestionRequirement = cyQuestionRequirementService.selectCyQuestionRequirementById(id);
        mmap.put("cyQuestionRequirement", cyQuestionRequirement);
        return prefix + "/edit";
    }

    /**
     * 修改保存策义问卷调查：需求调查
     */
    @RequiresPermissions("system:requirement:edit")
    @Log(title = "策义问卷调查：需求调查", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CyQuestionRequirement cyQuestionRequirement)
    {
        return toAjax(cyQuestionRequirementService.updateCyQuestionRequirement(cyQuestionRequirement));
    }

    /**
     * 删除策义问卷调查：需求调查
     */
    @RequiresPermissions("system:requirement:remove")
    @Log(title = "策义问卷调查：需求调查", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cyQuestionRequirementService.deleteCyQuestionRequirementByIds(ids));
    }
}
